package main.meniu;

import java.io.InputStream;

import orfeu.engine.R;
import orfeu.engine.SpriteGameActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Meniu extends Activity {	    
    
	@Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        //TextView tv = new TextView(this);
		//tv.setText("New game");
		setContentView(R.layout.meniu);
		addContentView(new GIFView(this), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		ImageView  imv1=(ImageView)findViewById(R.id.imageView1);
		imv1.setOnClickListener(new View.OnClickListener() {			

			public void onClick(View arg0) {
				Intent myIntent = new Intent(Meniu.this,SpriteGameActivity.class);
				startActivity(myIntent);
			}
		});
		///////
		ImageView help = (ImageView)findViewById(R.id.imageView5);
		help.setOnClickListener(new View.OnClickListener() {	
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent myIntent = new Intent(Meniu.this, HelpActivity.class);
				startActivity(myIntent);
			}
		});
		/////
		ImageView  imv2=(ImageView)findViewById(R.id.imageView2);
		imv2.setOnClickListener(new View.OnClickListener() {			
			

			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		
    }
    private static class GIFView extends View{    	
    	Movie movie1, movie2,movie3;

    	public static float width;
    	InputStream is1 = null;
    	InputStream is2 = null;
    	InputStream is3 = null;
    	long moviestart1;
    	long moviestart2;
    	long moviestart3;
		public GIFView(Context context) {
			super(context);
			is1 = context.getResources().openRawResource(R.drawable.orfeusgrey);
			is2 = context.getResources().openRawResource(R.drawable.flame);
			is3 = context.getResources().openRawResource(R.drawable.buttom3);
			movie1 = Movie.decodeStream(is1);
			movie3 = Movie.decodeStream(is3);
			movie2 = Movie.decodeStream(is2);
		}
		
    	@Override
    	protected void onDraw(Canvas canvas) {
    		super.onDraw(canvas);	    		
    		long now = android.os.SystemClock.uptimeMillis();
        		
    		if (moviestart1 == 0) {   // first time
                 moviestart1 = now;
            }   
    		if (moviestart2 == 0) {   // first time
                moviestart2 = now;
           }
    		if (moviestart3 == 0) {   // first time
                moviestart3 = now;
           }
    		width=135;  
    		int relTime = (int)((now - moviestart2) % movie2.duration()) ;
    		movie2.setTime(relTime);
    		movie2.draw(canvas,width-40, 50);
    		relTime = (int)((now - moviestart3) % movie3.duration()) ;
    		movie3.setTime(relTime);
    		movie3.draw(canvas,width-130, 680);
    		relTime = (int)((now - moviestart1) % movie1.duration()) ; 
    		movie1.setTime(relTime);
    		  		
            movie1.draw(canvas,width-80, 0);
    		
    		this.invalidate();
    	}    	    	    	
    }	
    
    
    @Override
    public void onStop()
    {
    	super.onStop();
    	System.runFinalizersOnExit(true);
    }
    
    public void onDestroy()
    {
    	super.onDestroy();
    	System.runFinalizersOnExit(true);
    }
}


